// create by:吴渭明
// create time:2014-04-23 16:36:39
//获取id
function gId(field,ero){return '#'+syChartId+'_'+ero+'_form_'+field;}
//页面启动时
function syChartonload(){
}

//打开新建页面时
function syChartAddOnOpen(){
	eSet(gId('createuser','add'),getCurrentUserId());
}

//打开编辑页面时
function syChartEditOnOpen(){
	eSet(gId('createuser','edit'),getCurrentUserId());
}

//点击新建按钮时
function AddBtnClick(){
	return true;
}
//点击编辑按钮时
function EditBtnClick(){
	return true;
}

function getChart_data(str){
	var reg = "\/\/数据开始([\\s\\S]+)\/\/数据结束";
	return str.match(reg)[1];
}

function initChart(systitle,title, url,chartUrl,charData){
	var eChart_obj=null;
	var eChart = $.window({
		title: title,
		url: top.sysPath + url + '?topthemeName=' + top.themeName,
		isIframe: true,
		width: $(top).width(),
		height: $(top).height() - 60,
		left: 0,
		top: 60,
		winId: 'eChart'+new Date().getTime(),
		target: 'top',
		maximizable: true,
		minimizable: true,
		buttons: [{
			text: '保存至系统',
			handler: function() {
				if(eChart_obj==null)return;
				var setData={
					chartHtml:ttoh(eChart_obj.getCode()).replaceAll('<br>','\n'),
					chartTitle:systitle
				};
				data(getUrl('syChart', 'Set_Chart'), setData, 'json', null);
			}
		}],
		onComplete: function() {
			eChart_obj = eChart.find('iframe')[0].contentWindow;
			eChart_obj.setChartData(charData);
		}
	});
}


function editChart(systitle,title, url,chartUrl) {
	var charData=null;
	$.get(top.sysPath+chartUrl)
.success(function(dx) { 
		charData=eval('('+getChart_data(dx)+')');
		initChart(systitle,title, url,chartUrl,charData);
	})
.error(function() {
	charData=null;
	initChart(systitle,title, url,chartUrl,charData);
	})
}